<template>
    <view class="components-category-popup-container">
		<!-- v-for="(item, index) in 5" :key="index" -->
		<view class="category-popup-title-container">选择分类</view>
		<!-- 遍历 两种类型 一个是支出 一个是收入 -->
		<view class="category-popup-content-pay-left-category-container" >
			<!-- 每个账本下的分类 -->
			<view :class="['category-popup-content-pay-left-category-item', {'select-category': index == selectIndex}, {'not-select': index != selectIndex}]" 
				v-for="(item, index) in categoryList2" :key="index" :style="{width: item.width} + 'rpx'" @click="selectCategory(item, index)">
				<view :class="['category-popup-content-pay-left-category-item-left-icon', 'iconfont', item.icon]" :style="{color: item.iconColor}"></view>
				<view class="category-popup-content-pay-left-category-item-right-name">{{item.name}}</view>
			</view>
		</view>
    </view>
</template>

<script>
	import {checkStrType} from '@/util/regular/regular.js';
	import {checkStrType2} from '@/util/regular/regular.js';
    export default {
		props: {
			categoryList: {
				type: Array,
				default: () => []
			},
			selectIndex: {
				type: Number,
				default: -1,
			}
		},
        data() {
            return {
				categoryList2: [],								// 测试宽度使用
				type: ['pay', 'income'],
				list: [],
            }
        },
		methods: {
			/** 选择分类回调事件
			 * @param {Object} item 分类集合
			 * @param {Object} index 索引
			 */
			selectCategory(item, index) {
				this.$emit("selectCategoryCallback", item, index);
			}
		},
		mounted() {
			this.categoryList2 = JSON.parse(JSON.stringify(this.categoryList));
			this.categoryList2.forEach(item => item.width = checkStrType2(item.name, 45, 30));
		},
    }
</script>

<style lang="scss">
	.components-category-popup-container {
		width: 660rpx;
		// 后续改为由分类撑开，因为不知道有几个分类
		min-height: 700rpx;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: center;
		padding: 30rpx 0rpx;
		box-sizing: border-box;
		
		.category-popup-title-container {
			width: 100%;
			height: 50rpx;
			text-align: center;
			line-height: 50rpx;
		}
		
		.category-popup-content-pay-left-category-container {
			width: 100%;
			display: flex;
			padding: 0rpx 20rpx;
			box-sizing: border-box;
			justify-content: flex-start;
			align-items: flex-start;
			flex-wrap: wrap;
			margin-top: 20rpx;
			
			.category-popup-content-pay-left-category-item {
				height: 50rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 10rpx 20rpx;
				border-radius: 40rpx;
				// color: $typefaceGreyColor;
				
				margin-right: 20rpx;
				box-shadow: 0px 0px 2px #dfdede;
				margin-bottom: 20rpx;
				
				.category-popup-content-pay-left-category-item-left-icon {
					font-size: 40rpx;
					margin-right: 10rpx;
				}
				.category-popup-content-pay-left-category-item-right-name {
					font-size: 22rpx;
				}
			}
			
			.select-category {
				background-color: $themeYellowColor;
			}
			
			.not-select {
				background-color: $themeBgcLightGreyColor;
			}
		}
		
	}
</style>
